package com.tengju.bff.infrastructure.export.repo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tengju.bff.infrastructure.export.convert.PersonalGiveConvert;
import com.tengju.bff.interfaces.covercharge.entity.vo.PersonalGiveQuery;
import com.tengju.bff.interfaces.covercharge.entity.vo.PersonalGiveVo;
import com.tengju.bff.interfaces.covercharge.service.IServiceLetaxWithdrawLogService;
import com.tengju.bff.interfaces.shared.export.PersonalGiveExportQuery;
import com.tengju.export.domain.record.ExportDataSourceRepository;
import com.tengju.export.domain.record.Query;
import com.tengju.export.domain.record.Table;
import com.tengju.user.application.user.UserDataAuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 李大仙
 * @date: 2021/8/23 2:39 下午
 */
@Service("personalGiveExportDataSourceRepository")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class PersonalGiveExportDataSourceRepository implements ExportDataSourceRepository {

    private final IServiceLetaxWithdrawLogService serviceLetaxWithdrawLogService;
    private final UserDataAuthService userDataAuthService;

    @Override
    public Table batchFindDataSource(Query query) {
        PersonalGiveExportQuery exportQuery = (PersonalGiveExportQuery) query;
        PersonalGiveQuery personalGiveQuery = new PersonalGiveQuery();
        personalGiveQuery.setPageNo(exportQuery.getPageNo());
        personalGiveQuery.setLimit(exportQuery.getLimit());
        personalGiveQuery.setCycleDate(exportQuery.getCycleDate());
        personalGiveQuery.setAuthType(exportQuery.getAuthType());
        personalGiveQuery.setStatus(exportQuery.getStatus());
        personalGiveQuery.setLetaxStatus(exportQuery.getLetaxStatus());

        Page<PersonalGiveVo> personalGiveVoPage = serviceLetaxWithdrawLogService.queryPersonalGiveList(new Page<>(exportQuery.getPageNo(), exportQuery.getLimit()), personalGiveQuery);
        List<PersonalGiveVo> list = userDataAuthService.dataMasking(personalGiveVoPage.getRecords(), exportQuery.getStaffId());

        return PersonalGiveConvert.convert(list, personalGiveQuery.getAuthType());
    }
}
